package cn.wolfcode.web.controller;


import cn.wolfcode.domain.MessageReplyHjc;
import cn.wolfcode.service.IMessageReplyHjcService;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.util.PermissionAnnotation;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ModelAttribute;

@Controller
@RequestMapping("/messageReplyHjc")
public class MessageReplyHjcController {

    @Autowired
    private IMessageReplyHjcService messageReplyHjcService;


    @PermissionAnnotation(name="留言详情页面",expression="messageReplyHjc:list")
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo<MessageReplyHjc> pageInfo = messageReplyHjcService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "messageReplyHjc/list";
    }


    @PermissionAnnotation(name="留言详情删除",expression="messageReplyHjc:delete")
    @RequestMapping("/delete")
    public String delete(Long id) {
        if (id != null) {
           messageReplyHjcService.delete(id);
        }
        return "redirect:/messageReplyHjc/list";
    }


    @PermissionAnnotation(name="留言详情新增/编辑",expression="messageReplyHjc:saveOrUpdate")
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(MessageReplyHjc messageReplyHjc) {
        if (messageReplyHjc.getId() == null) {
            messageReplyHjcService.save(messageReplyHjc);
        } else {
            messageReplyHjcService.update(messageReplyHjc);
        }
        return "redirect:/messageReplyHjc/list";
    }


    @PermissionAnnotation(name="留言详情新增/编辑",expression="messageReplyHjc:saveOrUpdate")
    @RequestMapping("/input")
    public String input(Long id, Model model) {
        if (id != null) {
            model.addAttribute("messageReplyHjc",messageReplyHjcService.get(id));
        }
        return "messageReplyHjc/input";
    }
}
